package com.hjy.dao;

import com.hjy.pojo.Department;
import com.hjy.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Repository
public class EmployeeDao {
    private static Map<Integer, Employee> employeeMap;

    @Autowired
    private static DepartmentDao departmentDao;
    static {
        employeeMap = new HashMap<Integer, Employee>();
        employeeMap.put(1001,new Employee(1001,"AA","A2402668109@qq.com",0,new Department(101,"市场部"),new Date()));
        employeeMap.put(1002,new Employee(1002,"BB","B2402668109@qq.com",1,new Department(102,"教学部"),new Date()));
        employeeMap.put(1003,new Employee(1003,"CC","C2402668109@qq.com",1,new Department(102,"教学部"),new Date()));
        employeeMap.put(1004,new Employee(1004,"DD","D2402668109@qq.com",0,new Department(104,"运营部"),new Date()));
        employeeMap.put(1005,new Employee(1005,"EE","E2402668109@qq.com",0,new Department(103,"教研部"),new Date()));
        employeeMap.put(1006,new Employee(1006,"FF","F2402668109@qq.com",0,new Department(105,"后勤部"),new Date()));
    }

    private static Integer theId = 1007;

    public Collection<Employee> findAll(){
        return employeeMap.values();
    }

    public Employee findById(Integer id){
        return employeeMap.get(id);
    }

    public Employee insert(Employee employee){
        if (employee!=null){
            employee.setId(theId);
            employeeMap.put(theId++,employee);
        }
        return employee;
    }

    public Employee delete(Integer id){
        return employeeMap.remove(id);
    }

    public Employee update(Employee employee){
        employeeMap.put(employee.getId(),employee);
        return employee;
    }
}
